#include <cstdio>
#include <algorithm>
#include <utility>

using namespace std;

static const int MAX_N = 250000;
int val[MAX_N];         // score
long long psum[MAX_N];  // partial sum of positive numbers

int main() {
    FILE *fin = fopen("hop.in", "r");
    FILE *fout = fopen("hop.out", "w");
    static pair<int, long long> deque[MAX_N + 1];
         /* the first element of the pair is the index, and the
            second is the max score we can get */

    pair<int, long long> *ds = deque, *de = deque;
    *de++ = make_pair(-1, 0);   // we mark the first element (empty) indexed -1

    int n;
    fscanf (fin, "%d", &n);
    int k;
    fscanf (fin, "%d", &k);
    long long maxval = 0;                           // the answer to be

    for(int i = 0; i != n; ++i)
        fscanf(fin, "%d", val + i);

    psum[0] = max(0, val[0]);

    for (int i = 1; i != n; ++i)
        psum[i] += psum[i - 1] + max(0, val[i]);

          // calculate the partial sum of positive numbers:
        long long toadd = 0;    /* Record the elements to be pushed
                                   into the deque in the next loop */
    for (int i = 0; i != n; ++i) {
        for (; ds != de && ds->first + k < i; ++ds);  /* pop back
                                if the index > current index - k */
        long long cur = ds->second + val[i] + (i == 0 ? 0 :
                psum[i - 1]) - (ds->first == -1 ? 0 : psum[ds->first + 1]);
        maxval = max(maxval, cur);
        if(i != n - 1) maxval = max(maxval, cur + val[i + 1]);
        if(i != 0) {
            while (ds != de &&
                    toadd > de[-1].second + psum[i] - psum[de[-1].first + 1])
                        // Pop front if no longer be better
                --de;
                *de++ = make_pair(i - 1, toadd);
                        // instead of dp, we push it into the deque
        }
        toadd = cur + val[i + 1];
    }
    fprintf (fout, "%lld\n", maxval);
    return 0;
}
